package com.link2room.rodimus.controller.inside;


import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.rodimus.facade.IPointFacadeService;
import com.link2room.rodimus.dto.param.base.PointBaseParamDto;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * Created by VegetaKo on 2017/3/20.
 */
@Api(tags = "积分相关")
@RestController
@RequestMapping("/in/Points")
public class PointInsideController {

    @Resource
    private IPointFacadeService pointFacadeService;

    @RequestMapping(value="/PointRules/CheckPoint",method = RequestMethod.GET)
    public BaseResultDto pointRule(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode,
            @RequestParam(value = "pointRuleCode" ,required = true) String pointRuleCode,
            @RequestParam(value = "l2rMemberNo" ,required = true) String l2rMemberNo,
            @RequestParam(value = "totalPriceSale" ,required = true) BigDecimal totalPriceSale,
            @RequestParam(value = "arrDateStr" ,required = true) String arrDateStr,
            @RequestParam(value = "depDateStr" ,required = true) String depDateStr
    ) throws Exception {
        PointBaseParamDto pointBaseParamDto = new PointBaseParamDto();
        pointBaseParamDto.setLhotelCode(lhotelCode);
        pointBaseParamDto.setPointRuleCode(pointRuleCode);
        pointBaseParamDto.setL2rMemberNo(l2rMemberNo);
        pointBaseParamDto.setTotalPriceSale(totalPriceSale);
        pointBaseParamDto.setArrDateStr(arrDateStr);
        pointBaseParamDto.setDepDateStr(depDateStr);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(pointFacadeService.checkPointUse(pointBaseParamDto));
        return resDto;
    }

    @RequestMapping(value="/Point",method = RequestMethod.PUT)
    public BaseResultDto pointUse(
            @RequestBody PointBaseParamDto pointBaseParamDto
            ) throws Exception {
        pointFacadeService.usePoint(pointBaseParamDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value="/Point",method = RequestMethod.POST)
    public BaseResultDto pointAdd(
            @RequestBody PointBaseParamDto pointBaseParamDto
    ) throws Exception {
        pointFacadeService.addPoint(pointBaseParamDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }
}
